package com.yneusoft.pctask.controller;

import com.yneusoft.common.model.ResponseWrapper;
import com.yneusoft.pctask.model.*;
import com.yneusoft.pctask.service.StaffManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @Description： 员工信息请求层
 * @Author: zwl
 * @Date: 2021/11/24 19:02
 */
@RestController
@CrossOrigin
@RequestMapping("/staffManage")
@Slf4j
public class StaffManageController {

    @Autowired
    private StaffManageService staffManageService;

    /**
     * 1、获取员工状态列表
     * @return   员工状态信息列表
     */
    @GetMapping("/getStaffStateList")
    public ResponseWrapper getStaffStateList(){
        return staffManageService.getStaffStateList();
    }

    /**
     * 2、获取员工信息列表
     * @param pageSearchParam
     * @return  员工信息列表
     */
    @GetMapping("/getStaffList")
    public ResponseWrapper getStaffList(@Validated PageSearchParam pageSearchParam){
        return staffManageService.getStaffList(pageSearchParam);
    }

    /**
     * 3、员工离职/重新入职
     * @param updateStaffStateParam
     * @return  修改的信息
     */
    @PostMapping("/updateStaffState")
    public ResponseWrapper updateStaffState(@Validated @RequestBody UpdateStaffStateParam updateStaffStateParam){
        return staffManageService.updateStaffState(updateStaffStateParam);
    }

    /**
     * 4、【新增/修改】获取部门列表
     * @return 部门信息列表
     */
    @GetMapping("/getDepartmentInfoList")
    public ResponseWrapper getDepartmentInfoList(){
        return staffManageService.getDepartmentInfoList();
    }

    /**
     * 5、【新增/修改】修改时获取员工信息
     * @param staffListParam
     * @return  员工信息
     */
    @GetMapping("/getStaffInfo")
    public ResponseWrapper getStaffInfo(@Validated StaffListParam staffListParam){
        return staffManageService.getStaffInfo(staffListParam);
    }

    /**
     * 6、【新增/修改】新增/员工信息
     * @return  code / message / data
     */
    @PostMapping("/saveStaffInfo")
    public ResponseWrapper saveStaffInfo(@Validated @RequestBody SaveStaffInfoParam saveStaffInfoParam){
        return staffManageService.saveStaffInfo(saveStaffInfoParam);
    }


    /**
     * 7、【新增/修改】检查身份证号是否重复
     * @param checkIdNumberStaffParam
     * @return 员工信息 / false
     */
    @GetMapping("/checkIdNumberIsExist")
    public ResponseWrapper checkIdNumberIsExist(@Validated CheckIdNumberIsExistParam checkIdNumberStaffParam){
        return staffManageService.checkIdNumberIsExist(checkIdNumberStaffParam);
    }

    /**
     * 8、【新增/修改】检查手机号是否存在
     * @param checkPhoneStaffParam
     * @return  员工信息 / true / false
     */
    @GetMapping("/checkPhoneIsExist")
    public ResponseWrapper checkPhoneIsExist(@Validated CheckStaffPhoneParam checkPhoneStaffParam){
        return staffManageService.checkPhoneIsExist(checkPhoneStaffParam);
    }

    /**
     * 9、【新增/修改】上传员工附件
     * @param param 员工aid和附件
     * @return 附件id和附件名称
     */
    @PostMapping("/uploadStaffFile")
    public ResponseWrapper uploadStaffFile(UploadStaffFileParam param){
        return staffManageService.uploadStaffFile(param);
    }

    /**
     * 10、【新增/修改】删除员工附件
     * @param param 员工aid、附件id
     * @return 操作结果
     */
    @PostMapping("/delStaffFile")
    public ResponseWrapper delStaffFile(@Validated @RequestBody DeleteStaffFileParam param) {
        return staffManageService.delStaffFile(param);
    }

    /**
     * 11、下载员工附件
     * @param response 请求对象
     * @param enclosureId 附件id
     * @return 附件下载
     */
    @GetMapping("/downloadStaffFile")
    public ResponseWrapper downloadFile(HttpServletResponse response, String enclosureId) {
        return staffManageService.downloadFile(response,enclosureId);
    }

}
